/*
 * ds3232.c
 *
 * Created: 14.01.2013 16:47:16
 *  Author: saenko
 */ 
#include <avr/interrupt.h>

#include "twi.h"
#include "ds3232.h"





void ad3232_init(void)
{
	EICRA = (1<<ISC00);
	EIMSK = (1<<INT0);
}

unsigned char ad3232_get_sec(void)
{
	twi_buf[0] = 0x00;
	twi_start(0b11010000, TX_TWI, 1);
	
	while(!twi_flags.transmit_end);
	twi_flags.transmit_end = 0;
	
	twi_start(0b11010000, RX_TWI, 1);
	while(!twi_flags.receive_end);
	twi_flags.receive_end = 0;
	return twi_buf_rx[0];
}

void ad3232_get_time(void)
{
	twi_buf[0] = 0x01;
	twi_start(0b11010000, TX_TWI, 1);
	
	while(!twi_flags.transmit_end);
	twi_flags.transmit_end = 0;
	
	twi_start(0b11010000, RX_TWI, 2);
}

void ad3232_set_time(unsigned char hh, unsigned char mm)
{
	twi_buf[0] = 0x01;
	twi_buf[1] = mm;
	twi_buf[2] = hh;
	twi_start(0b11010000, TX_TWI, 3);
	
	while(!twi_flags.transmit_end);
	twi_flags.transmit_end = 0;
	

}

